"""
已知：
    （1）有A箱子，红球概率40%；
    （2）有B箱子，红球概率20%；
    （3）随机选择A箱子或B箱子。
问题：
    如果取到1个红球，那么此红球来自A箱子的概率是多少？

1亿次模拟大概在66%。
"""

import random

POT_1 = ["r", "r", "r", "r", "b", "b", "b", "b", "b", "b"]
POT_2 = ["r", "r", "b", "b", "b", "b", "b", "b", "b", "b"]
POT_LIST = [POT_1, POT_2]

TOTAL_COUNT = 0
RED_COUNT = 0
RED_FROM_POT_1 = 0

while TOTAL_COUNT < 100000000:
    if TOTAL_COUNT % 1000000 == 0:
        print(f"Has been {TOTAL_COUNT} times. Please wait...")

    player_get_pot = random.choice(POT_LIST)
    player_get_ball = random.choice(player_get_pot)
    TOTAL_COUNT += 1

    if player_get_ball == "r":
        RED_COUNT += 1

        if player_get_pot == POT_1:
            RED_FROM_POT_1 += 1

probability = round((RED_FROM_POT_1 / RED_COUNT) * 100, 2)

print(f"Total count: {TOTAL_COUNT}; RED_FROM_POT_1: {RED_FROM_POT_1}, probability: {probability}%.")
